//
//  MyselfView.m
//  心水宝典
//
//  Created by zr on 2018/8/28.
//  Copyright © 2018年 zr. All rights reserved.
//

#import "MyselfView.h"


@interface MyselfView ()

@property (nonatomic, strong)UIButton * oneButton;
@property (nonatomic, strong)UIButton * twoButton;
@property (nonatomic, strong)UIButton * threeButton;
@property (nonatomic, strong)UIButton * fourButton;
@property (nonatomic, strong)UIButton * fiveButton;
@property (nonatomic, strong)UIButton * sixButton;
@property (nonatomic, strong)UIButton * sevenButton;
@property (nonatomic, strong)UIButton * eightButton;
@property (nonatomic, strong)UILabel * oneLabel;
@property (nonatomic, strong)UILabel * twoLabel;
@property (nonatomic, strong)UILabel * threeLabel;
@property (nonatomic, strong)UILabel * fourLabel;
@property (nonatomic, strong)UILabel * fiveLabel;
@property (nonatomic, strong)UILabel * sixLabel;
@property (nonatomic, strong)UILabel * sevenLabel;
@property (nonatomic, strong)UILabel * eightLabel;
@property (nonatomic, strong)UIView * lineView;
@property (nonatomic, strong)UIView * verOneLineView;
@property (nonatomic, strong)UIView * verTwoLineView;
@property (nonatomic, strong)UIView * verThreeLineView;

@end

@implementation MyselfView

- (instancetype)initWithFrame:(CGRect)frame{
    
    if ([super initWithFrame:frame]) {
        
        [self setupUI];
    }
    
    return self;
}


- (void)setupUI{
    
    self.backgroundColor = WHITE_COLOR;
    
    self.oneButton = [self setupButtonWith:@"dongtai"];
    [self addSubview:self.oneButton];
    
    self.twoButton = [self setupButtonWith:@"huifu"];
    [self addSubview:self.twoButton];
    
    self.threeButton = [self setupButtonWith:@"shoucang"];
    [self addSubview:self.threeButton];
    
    self.fourButton = [self setupButtonWith:@"xiaoxi1"];
    [self addSubview:self.fourButton];
    
    self.oneLabel = [self setupLabelWith:@"我的动态"];
    [self addSubview:self.oneLabel];
    
    self.twoLabel = [self setupLabelWith:@"我的回复"];
    [self addSubview:self.twoLabel];
    
    self.threeLabel = [self setupLabelWith:@"我的收藏"];
    [self addSubview:self.threeLabel];
    
    self.fourLabel = [self setupLabelWith:@"消息中心"];
    [self addSubview:self.fourLabel];
    
    
    self.fiveButton = [self setupButtonWith:@"fankui"];
    [self addSubview:self.fiveButton];
    
    self.sixButton = [self setupButtonWith:@"happinh"];
    [self addSubview:self.sixButton];
    
    self.sevenButton = [self setupButtonWith:@"huancun"];
    [self addSubview:self.sevenButton];
    
    self.eightButton = [self setupButtonWith:@"shezhi"];
    [self addSubview:self.eightButton];
    
    self.fiveLabel = [self setupLabelWith:@"意见反馈"];
    [self addSubview:self.fiveLabel];
    
    self.sixLabel = [self setupLabelWith:@"给个好评"];
    [self addSubview:self.sixLabel];
    
    self.sevenLabel = [self setupLabelWith:@"清理缓存"];
    [self addSubview:self.sevenLabel];
    
    self.eightLabel = [self setupLabelWith:@"设置"];
    [self addSubview:self.eightLabel];
    
}


- (void)layoutSubviews{
    
    [self.oneButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self).offset(33 * SCREENH6);
        make.height.width.mas_equalTo(25 * SCREENH6);
        make.top.mas_equalTo(self).offset(23 * SCREENH6);
    }];
    
    [self.oneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.oneButton);
        make.top.mas_equalTo(self.oneButton.mas_bottom).offset(8 * SCREENH6);
    }];
    
    [self.twoButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.oneButton);
        make.height.mas_equalTo(25 * SCREENH6);
        make.width.mas_equalTo(22 * SCREENH6);
        make.leading.mas_equalTo(self.oneButton.mas_trailing).offset(70 * SCREENH6);
    }];
    
    [self.twoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.twoButton);
        make.centerY.mas_equalTo(self.oneLabel);
    }];
    
    [self.threeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.twoButton);
        make.height.mas_equalTo(25 * SCREENH6);
        make.width.mas_equalTo(26 * SCREENH6);
        make.leading.mas_equalTo(self.twoButton.mas_trailing).offset(70 * SCREENH6);
    }];
    
    [self.threeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.threeButton);
        make.centerY.mas_equalTo(self.twoLabel);
    }];
    
    [self.fourButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.threeButton);
        make.height.mas_equalTo(25 * SCREENH6);
        make.width.mas_equalTo(28 * SCREENH6);
        make.leading.mas_equalTo(self.threeButton.mas_trailing).offset(67 * SCREENH6);
    }];
    
    [self.fourLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.fourButton);
        make.centerY.mas_equalTo(self.threeLabel);
    }];

    [self.fiveButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.oneButton);
        make.height.mas_equalTo(26 * SCREENH6);
        make.width.mas_equalTo(23 * SCREENH6);
        make.top.mas_equalTo(self.oneLabel.mas_bottom).offset(45 * SCREENH6);
    }];
    
    [self.fiveLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.fiveButton);
        make.top.mas_equalTo(self.fiveButton.mas_bottom).offset(8 * SCREENH6);
    }];
    
    [self.sixButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.fiveButton);
        make.height.mas_equalTo(24 * SCREENH6);
        make.width.mas_equalTo(32 * SCREENH6);
        make.centerX.mas_equalTo(self.twoButton);
    }];
    
    [self.sixLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.sixButton);
        make.centerY.mas_equalTo(self.fiveLabel);
    }];
    
    [self.sevenButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(25 * SCREENH6);
        make.width.mas_equalTo(22 * SCREENH6);
        make.centerY.mas_equalTo(self.sixButton);
        make.centerX.mas_equalTo(self.threeButton);
    }];
    
    [self.sevenLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.sevenButton);
        make.centerY.mas_equalTo(self.sixLabel);
    }];
    
    [self.eightButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.sevenButton);
        make.height.mas_equalTo(26 * SCREENH6);
        make.width.mas_equalTo(26 * SCREENH6);
        make.centerX.mas_equalTo(self.fourButton);
    }];
    
    [self.eightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.eightButton);
        make.centerY.mas_equalTo(self.sevenLabel);
    }];
}


- (UIView *)setupLineView{
    
    UIView * lineView = [UIView new];
    
    lineView.backgroundColor = ColorWithRGB(0xe6e6e6);
    
    return lineView;
}

- (UILabel *)setupLabelWith:(NSString *)string{
    
    UILabel * label = [UILabel new];
    
    label.textColor = BLACK_COLOR;
    label.font = [UIFont systemFontOfSize:13 * SCREENH6];
    label.text = string;
    label.textAlignment = NSTextAlignmentCenter;
    
    return label;
}

- (UIButton *)setupButtonWith:(NSString *)string{
    
    UIButton * button = [UIButton new];
    
    [button setImage:ImageNamed(string) forState:UIControlStateNormal];
    [button addTarget:self action:@selector(ClickButton:) forControlEvents:UIControlEventTouchUpInside];
    
    return button;
}


- (void)ClickButton:(UIButton *)button{
    
    NSString * type;
    
    if (button == self.oneButton) {
        
        type = @"one";
    }else if (button == self.twoButton){
        
        type = @"two";
    }else if (button == self.threeButton){
        
        type = @"three";
    }else if (button == self.fourButton){
        
        type = @"four";
    }else if (button == self.fiveButton){
        
        type = @"five";
    }else if (button == self.sixButton){
        
        type = @"six";
    }else if (button == self.sevenButton){
        
        type = @"seven";
    }else if (button == self.eightButton){
        
        type = @"eight";
    }
    
    NSDictionary * dict = @{@"type":type};
    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"ClickMyselfViewButton" object:nil userInfo:dict];
}



@end
